package com.bw.gmallbi.service.impl;


import com.bw.gmallbi.bean.ProductStats;
import com.bw.gmallbi.mapper.ProductStatsMapper;
import com.bw.gmallbi.service.ProductStatsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

// Desc: 商品统计Service接口
@Service
public class ProductStatsServiceImpl implements ProductStatsService {

    @Resource
    private ProductStatsMapper productStatsMapper;

    @Override
    public BigDecimal getGMV(Integer date) {
        // 调用mapper
        return productStatsMapper.selectGMV(date);
    }

    @Override
    public List<ProductStats> getGMVByTm(Integer date, Integer limit) {
        return productStatsMapper.selectGMVByTm(date, limit);
    }

    @Override
    public List<ProductStats> getGMVByCt(Integer date, Integer limit) {
        // 品类销售
        List<ProductStats> productStats = productStatsMapper.selectGMVByCt(date, limit);
//        BigDecimal gmv = productStatsMapper.selectGMV(date);
//        List<Map<String,Double>> maps = new ArrayList<>();
//        for (ProductStats productStat : productStats) {
//            Map<String,Double>  map = new HashMap<>();
//            map.put(productStat.getCategory3_name(),productStat.getOrder_amount().doubleValue()/gmv.doubleValue())
//
//        }
        return productStats;
    }

    @Override
    public List<ProductStats> getProductStatsBySPU(Integer date, Integer limit) {
        return productStatsMapper.selectProductStatsBySPU(date,limit);
    }
}
